package come;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.net.Socket;

import javax.swing.JTextArea;

public class Receiver {
	private JTextArea jta;
	Socket socket;
	public Receiver(JTextArea jta) {
		this.jta = jta;
		socket=SocketUtil.getSocket();
	}

	public void startReceive(){
		new Thread(new Runnable() {
			
			@Override
			public void run() {
				socket=SocketUtil.getSocket();
				while(true){
					try {
						ObjectInputStream ois=new ObjectInputStream(socket.getInputStream());
						Object mess=ois.readObject();
						String str=(String) mess;
						jta.append("对方说："+str+"\n");
					} catch (IOException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					} catch (ClassNotFoundException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
			}
		}).start();
	}
}
